package com.first.order.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.first.common.pojo.EduCourse;
import com.first.common.pojo.TbPlayHistory;
import com.first.common.vo.Result;
import com.first.order.dao.TbPlayHistoryDao;
import com.first.order.service.TbPlayHistoryService;
import com.first.order.vo.TbMemberVo;
import com.first.order.vo.TbPlayHistoryVo;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

/**
 * @program: first-project
 * @description:
 * @author: 路志欣
 * @create: 2023-06-05 17:38
 **/
@Service
public class TbPlayHistoryServiceImpl implements TbPlayHistoryService {
    @Autowired
    private TbPlayHistoryDao tbPlayHistoryDao;

    //学习记录
    @Override
    public IPage<TbPlayHistory> findById(Integer pageCurrent, Integer pageSize, String memberId) {
        Page<TbPlayHistory> page = new Page<>(pageCurrent,pageSize);
        QueryWrapper<TbPlayHistory> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",memberId);
        IPage<TbPlayHistory> byId = tbPlayHistoryDao.findById(page,wrapper);
        return byId;
    }

    /**
     *
     * @param HuiYuanId
     * @param vedeoId
     * @return 添加学习记录
     */
    @Override
    public Integer insertPlayHistoryByCourseId(String HuiYuanId, String vedeoId) {
        TbPlayHistory tbPlayHistory = new TbPlayHistory();
        tbPlayHistory.setPlayId(IdUtil.getSnowflakeNextIdStr());
        tbPlayHistory.setPlayTimePoint(LocalDateTime.now());
        tbPlayHistory.setVedeoId(vedeoId);
        tbPlayHistory.setUserId(HuiYuanId);
        int insert = tbPlayHistoryDao.insert(tbPlayHistory);
        return insert;
    }


}
